package com.yifi.common.utils;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

public class DbUtils {

	public static boolean save(String tableName,String primaryKey,Record record,boolean isedit)
	{
		
		boolean tag = false;
		try {
			if (isedit) {
				tag = Db.update(tableName, primaryKey, record);
			} else {
				tag = Db.save(tableName, primaryKey, record);
			}
		} catch (Exception e) {
			System.out.println(e);
			return false;
		}
		return tag;
		 
	}

	public boolean save(String tableName,Record record,boolean isedit)
	{
		boolean tag = false;
		try {
			if (isedit) {
				tag = Db.update(tableName, record);
			} else {
				tag = Db.save(tableName, record);
			}
		} catch (Exception e) {
			System.out.println(e);
			return false;
		}
		return tag;
 
	}
	
	public static String getStr(String sql)
	{
		String str=Db.queryStr(sql);
		
		if(StringUtils.isNotNull(str))
		{
			return str;
		}
		else
		{
			return "";
		}
	}
}
